package com.linx.playAndroid.widget

import androidx.annotation.Px
import androidx.compose.foundation.Image
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import coil.annotation.ExperimentalCoilApi
import coil.compose.rememberImagePainter
import coil.transform.RoundedCornersTransformation

/**
 * @Description:
 * @Author: 吴祖清
 * @CreateDate: 14.2.22 9:43 上午
 */
@OptIn(ExperimentalCoilApi::class)
@Composable
fun NetImage(
    url: String,
    contentScale: ContentScale = ContentScale.Fit,
    modifier: Modifier,
    @Px roundedCorners: Float = 0f
) {
    Image(
        painter = rememberImagePainter(
            //第三方图片控件coil里的一个方法
            data = url,                                          //data是数据源，可以是url也可以是drawable资源
            builder = {
                if (roundedCorners > 0)
                    transformations(
                        RoundedCornersTransformation(roundedCorners)          //圆角的转换
                    )
//                        placeholder(R.mipmap.oa_loading)                    //占位符
//                        error(R.mipmap.oa_app_all_default)                  //加载失败的图片
            },
            //在 ImagePainter 启动图像请求之前立即调用。 返回“true”以继续请求。 返回 'false' 以跳过执行请求。
        ),
        contentDescription = "网络加载图片",
        contentScale = contentScale,
        alignment = Alignment.Center,
        modifier = modifier
    )
}

